public class Solution {
    public int maxProfit(int[] prices) {
        int len = prices.length;

        int min = prices[0];
        int ret = 0;
        for (int i = 1; i < len; i++) {
            min = Math.min(prices[i], min);//找到前一部分的最小值
            ret = Math.max(ret, prices[i] - min);//当前的最大收益
        }

        return ret;
    }
}
